$(function(){
//	newFastClick(document.body);
	setTimeout(function(){
//		
		var mySwiper = new Swiper('.swiper-container',{
				autoHeight:true,
			    speed:0,
			   	hashnav:true,
				hashnavWatchState:true,
			    onSlideChangeStart: function(swiper){
			    	$(".navs a").removeClass('active');
			      	$(".navs a").eq(mySwiper.activeIndex).addClass('active');
			      
			      	var num=mySwiper.activeIndex*1+1;
			      	console.log("现在是第"+num+"页");
//			      	console.log($(".botbar").attr("class"));
			      document.body.scrollTop = document.documentElement.scrollTop = 0;
			     
			     }
			    
			  })
			$(".navs .Btnbutton").on('touchstart mousedown',function(e){
				e.preventDefault();
				$(".navs .Btnbutton").removeClass('active');
				$(this).addClass('active');
				mySwiper.slideTo($(this).index());
				
			})   
			
			$(".navs .Btnbutton").click(function(e){
			    e.preventDefault();
			    e.stopPropagation();
			    mySwiper.slideTo($(this).index());
			})
			
	},500)
	
})

$(function(){
	init();
				
				
	$(".unuse").click(function(){
		layer.msg("订单配送中，无法取消订单")
	})
})

//页面初始化
function init(){
	item1_type();
	item2_type();
}
			
	//借阅订单
	function item1_type(){
		var item1_length=$(".item1").length;
		var html='<div class="isnone">'+
				'<img src="../images/orders/isnone.png" />'+
				'<div>您还没有订单哦~</div>'+
				'</div>';
		if(item1_length==0){
			var hh=$(document).height();
			var h2=$(".top").height()+$(".navs").height()+$(".footer").height();
			$(".slide1").html(html).css("height",hh-h2);;
		}
		else{
			for(var i=0;i<item1_length;i++){
				var this_item=$(".item1").eq(i);
				//当前订单时候可取消
				var status=this_item.find(".status").val();
				//当前订单进度
				var rate=this_item.find(".rate").val();
				console.log(status+"*****"+rate);
				//判断
				if(status==0 && rate==0){
					var html='<input type="button" class="cancel" value="取消订单"  />'
					this_item.find(".timer").show();
					this_item.find(".itemrate").hide();
					this_item.find(".ibl_type1").show();
					this_item.find(".ibl_type2").hide();
					this_item.find(".i_bot_right").html(html);
							
				}else if(status==1){
							
					this_item.find(".timer").hide();
					this_item.find(".itemrate").show();
					var word1="订单配送中";var word2="订单已完成";
						if(rate==1){
								var html='<input type="button" class="unuse" readonly="readonly" value="取消订单"  />';
								this_item.find(".itemrate").text(word1);
								this_item.find(".ibl_type1").show();
								this_item.find(".ibl_type2").hide();
								this_item.find(".i_bot_right").html(html);
						}
						if(rate==2){
								var html='<input type="button" class="comment"  value="待评价"  />'
								this_item.find(".itemrate").text(word2);
								this_item.find(".ibl_type1").hide();
								this_item.find(".ibl_type2").show();
								this_item.find(".i_bot_right").html(html);
						} 
						if(rate==3){
								var html='';
								this_item.find(".itemrate").text(word2);
								this_item.find(".ibl_type1").hide();
								this_item.find(".ibl_type2").show();
								this_item.find(".i_bot_right").html(html);
						}
				}
			}
		}
		
	}
			
	function item2_type(){
		var words1="订单配送中";var words2="订单已完成";
		var qrsh="<input type='button' class='qrsh' value='确认收货' name='qrsh'/>";
		var dpj="<input type='button' class='dpj' value='待评价' name='dpj'/>";
		var zjpj="<input type='button' class='zjpj' value='追加评价' name='zjpj'/>";
		
		var item2_length=$(".item2").length;
		var html='<div class="isnone">'+
				'<img src="../images/orders/isnone.png" />'+
				'<div>您还没有订单哦~</div>'+
				'</div>';
		if(item2_length==0){alert(0);
			var hh=$(document).height();
			var h2=$(".top").height()+$(".navs").height()+$(".footer").height();console.log(h2);
			$(".slide2").html(html).css("height",hh-100);
			
		}else{
			for(var i=0;i<item2_length;i++){
				var this_item2=$(".item2").eq(i);
				var rate=this_item2.find(".rate").val();
				//判断显示的样式 头部进度条和顶部按钮
				if(rate==0){
					//目前没有这种情况  
				}
				if(rate==1){
					this_item2.find(".itemrate").text(words1);
					this_item2.find(".i_bot2_bot").html(qrsh);
				}
				if(rate==2){
					this_item2.find(".itemrate").text(words2);
					this_item2.find(".i_bot2_bot").html(dpj);
				}
				if(rate==3){
					this_item2.find(".itemrate").text(words2);
					this_item2.find(".i_bot2_bot").html(zjpj);
				}
				if(rate==4){
					this_item2.find(".itemrate").text(words1);
					this_item2.find(".i_bot2_bot").remove();
				}
				//计算数量和金额
				var i_con_length=this_item2.find(".i_c_con2").length;
				var amount=0;var total=0;
				for(var j=0;j<i_con_length;j++){
					this_i_con=this_item2.find(".i_c_con2").eq(j);
					var num=this_i_con.find(".num").text()*1;
					var price=this_i_con.find(".price").text()*1;
					amount=amount+num;
					total=total+num*price;
				}
				
				total=total.toFixed(2);
				this_item2.find(".amount").text(amount);
				this_item2.find(".total").text(total);
				
				
			}
			
		}
		
	}
